﻿@using BaBaoFan.Modifier.Model
@model IEnumerable<PoolInfoDto>
@{
    ViewData["Title"] = "八宝饭数据修改器";
}
<div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;">
        <div class="layui-btn-group btn-operation">
            @*<button class="layui-btn" data-type="getCheckData">获取选中行数据</button>*@
            <button class="layui-btn" id="btn-add" data-type="add">添加数据</button>
            <button class="layui-btn" data-type="deleteSelectAll">删除选中的</button>
            @*  <button class="layui-btn" data-type="isAll">验证是否全选</button>*@
        </div>
        <table lay-filter="poolInfo-table" id="poolInfoTable" hidden="hidden">
            <thead>
                <tr>
                    <th lay-data="{type:'checkbox', fixed: 'left'}"></th>
                    <th lay-data="{field:'id', width:100}">Id</th>
                    <th lay-data="{field:'poolName', width:150}">矿池名称</th>
                    <th lay-data="{field:'coins', width:150}">可挖币种</th>
                    <th lay-data="{field:'poolLogo', width:150}">矿池Logo</th>
                    <th lay-data="{field:'poolArea', width: 150}">矿池位置</th>
                    <th lay-data="{field:'poolPayTime', width:150}">矿池支付时间</th>
                    <th lay-data="{field:'poolAddress', width:150}">矿池Address</th>
                    <th lay-data="{field:'poolState', width: 150}">矿池状态</th>
                    <th lay-data="{field:'sort', width:150}">排序</th>
                    <th lay-data="{field:'poolDescription', width:150}">矿池描述</th>
                    <th lay-data="{field:'keyWords', width: 150}">关键字</th>
                    <th lay-data="{field:'poolScore', width: 150}">矿池评分</th>
                    <th lay-data="{field:'addTime', width:150}">添加时间</th>
                    <th lay-data="{field:'isVisable', width:150}">是否可见</th>
                    <th lay-data="{fixed: 'right', width:178, align:'center', toolbar: '#poolInfo-bar'}">操作</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                <tr>
                    <td></td>
                    <td>@item.Id</td>
                    <td>@item.PoolName</td>
                    <td>@item.FormatCoinInfos()</td>
                    <td>@item.PoolLogo</td>
                    <td>@item.PoolArea</td>
                    <td>@item.PoolPayTime</td>
                    <td>@item.PoolAddress</td>
                    <td>@item.PoolState</td>
                    <td>@item.Sort</td>
                    <td>@item.PoolDescription</td>
                    <td>@item.KeyWords</td>
                    <td>@item.PoolScore</td>
                    <td>@item.AddTime</td>
                    <td>@item.IsVisable</td>
                </tr>
                }
            </tbody>
        </table>

        <script type="text/html" id="poolInfo-bar">
            @*<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>*@
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
    </div>
</div>

<script>

    layui.use('table', function () {
        var table = layui.table;


        table.init('poolInfo-table', { //转化静态表格
            //height: 'full-500'
            page: true,
            limit: 20
        });
        //$("#millInfoTable").show();
        //监听工具条
        table.on('tool(poolInfo-table)', function (obj) {
            var row = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        type: 'POST',
                        url: '/PoolInfo/Delete',
                        data: { ids: row.id },
                        success: function (data) {
                            console.log(data);
                            if (data == "ok") {
                                obj.del();
                                layer.close(index);
                            }
                        },
                        //dataType: 'JSON'
                    });
                });
            } else if (obj.event === 'edit') {
                console.log(row.id);
                window.location.href = "/PoolInfo/Edit?id=" + row.id;
            }
        });

        var $ = layui.$, active = {

            add: function () {
                window.location.href = "/PoolInfo/Add";
            },

            deleteSelectAll: function () { //批量删除
                var checkStatus = table.checkStatus('poolInfoTable');
                data = checkStatus.data;
                if (data.length <= 0)
                    return;
                var list = [];

                for (var i = 0; i < data.length; i++) {
                    list[i] = data[i].id;
                }
                layer.confirm('确定删除这' + data.length + '列吗?', function () {
                    $.ajax({
                        type: 'POST',
                        url: '/PoolInfo/Delete',
                        data: { ids: list },
                        success: function (data) {
                            if (data == "ok") {
                                window.location.href = "/PoolInfo/List";
                            }
                        },
                        //dataType: 'JSON'
                    });
                });
            }
        };

        $('.btn-operation .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>
